package com.woniu.mealsService.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.woniu.dto.OrderLogDto;
import com.woniu.exception.meals.OrderException;
import com.woniu.mealsService.model.OrderLog;
import com.woniu.mealsService.mapper.OrderLogMapper;
import com.woniu.mealsService.service.OrderLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.utils.EnumException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单日志表 服务实现类
 * </p>
 *
 * @author jiang
 * @since 2024年12月09日
 */
@Service
public class OrderLogServiceImpl extends ServiceImpl<OrderLogMapper, OrderLog> implements OrderLogService {

    @Override
    public List<OrderLogDto> getOrderLog(String orderId) throws Exception {
        List<OrderLog> orderLogs = this.list(new LambdaQueryWrapper<OrderLog>().eq(OrderLog::getOrderId, orderId));
        if (orderLogs == null && orderLogs.isEmpty()){
            throw new OrderException(EnumException.ORDERLOG_ERROR_EXCEPTION);
        }
        List<OrderLogDto> orderLogDtos = BeanUtil.copyToList(orderLogs, OrderLogDto.class);
        return orderLogDtos;
    }
}
